/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.purpose.controller;

import com.koron.purpose.utils.BusinessCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.swan.bean.MessageBean;

import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.permission.SPIAccountAnno;
import com.koron.purpose.bean.JobsStaffBean;
import com.koron.purpose.service.api.JobsStaffService;
import com.koron.system.annotation.Log;
import com.koron.system.discrete.BusinessManipulation;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "jobsStaff", description = "人员岗位")
@RestController
@RequestMapping("/jobsStaff")
public class JobsStaffController {
    @Autowired
    private JobsStaffService service;

    @ApiOperation("删除")
    @ApiImplicitParam(name = "id", value = "id",  paramType = "query", dataType = "String")
    @RequestMapping(value = "/delete.htm", method = {RequestMethod.POST})
    @Log(title = "删除人员岗位信息", businessModule = "人员岗位", businessManipulation = BusinessManipulation.DELETE)
    public MessageBean<?> delete(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String id) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.delete(id);
    }

    @ApiOperation("详情")
    @ApiImplicitParam(name = "id", value = "id",  paramType = "query", dataType = "String")
    @RequestMapping(value = "/details.htm", method = {RequestMethod.GET})
    public MessageBean<?> details(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String id) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        if (StringUtils.isEmpty(id)) {
            id = user.getCode();
        }
        return service.details(id);
    }

    @ApiOperation("人员分配岗位")
    @RequestMapping(value = "/insert.htm", method = {RequestMethod.POST})
    @Log(title = "人员分配岗位", businessModule = "人员岗位", businessManipulation = BusinessManipulation.INSERT)
    public MessageBean<?> insert(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestBody JobsStaffBean bean) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.insert(bean, user);
    }

    @ApiOperation("修改")
    @RequestMapping(value = "/update.htm", method = {RequestMethod.POST})
    @Log(title = "修改人员岗位", businessModule = "人员岗位", businessManipulation = BusinessManipulation.UPDATE)
    public MessageBean<?> update(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestBody JobsStaffBean bean) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.update(bean, user);
    }

    @ApiOperation("查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deptCode", value = "部门code",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "当前页",  paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数",  paramType = "query", dataType = "Integer")})
    @RequestMapping(value = "/query.htm", method = {RequestMethod.GET})
    public MessageBean<?> query(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String deptCode,String name, Integer page, Integer pageSize) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.list(deptCode,name, page, pageSize);
    }

    @ApiOperation("人员任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "人员名称",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "jobsName", value = "岗位名称",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskTypeId", value = "任务类型",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "cycleId", value = "周期",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "当前页",  paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数",  paramType = "query", dataType = "Integer")})
    @RequestMapping(value = "/staffTaskList.htm", method = {RequestMethod.GET})
    public MessageBean<?> staffTaskList(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String name, String jobsName, String taskTypeId, String cycleId, Integer page, Integer pageSize) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.staffTaskList(name, jobsName, taskTypeId, cycleId, page, pageSize);
    }
}
